#include "stdafx.h"
#include "client_config.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include "debug_log.h"

void GetConfigPath(char *p_config_path, int config_path_size) {
	char current_path[256];
	char config_path[256];
	int config_path_len;

	ASSERT(NULL != p_config_path);
	GetCurrentDirectory(sizeof(current_path), current_path);
	strcpy(config_path, current_path);
	strcat(config_path, "\\alarmgui.ini");	
	config_path_len = strlen(config_path);
	ASSERT(config_path_len < config_path_size);
	strcpy(p_config_path, config_path);
}

void GetSocketGetIp(const char *p_config_path, char *p_socket_ip, int socket_ip_size) {
	int copy_byte;

	ASSERT(NULL != p_config_path && NULL != p_socket_ip && 0 < socket_ip_size);
	copy_byte = GetPrivateProfileString("socket_get", "ip", NULL, p_socket_ip, socket_ip_size, p_config_path);
	ASSERT(0 != copy_byte);
}

void GetSocketGetPort(const char *p_config_path, int *p_socket_port) {
	int socket_port;

	ASSERT(NULL != p_config_path && NULL != p_socket_port);
	socket_port = GetPrivateProfileInt("socket_get", "port", 0, p_config_path);
	ASSERT(0 != socket_port);
	*p_socket_port = socket_port;
}

void GetSocketShowIp(const char *p_config_path, char *p_socket_ip, int socket_ip_size) {
	int copy_byte;

	ASSERT(NULL != p_config_path && NULL != p_socket_ip && 0 < socket_ip_size);
	copy_byte = GetPrivateProfileString("socket_show", "ip", NULL, p_socket_ip, socket_ip_size, p_config_path);
	ASSERT(0 != copy_byte);
}

void GetSocketShowPort(const char *p_config_path, int *p_socket_port) {
	int socket_port;

	ASSERT(NULL != p_config_path && NULL != p_socket_port);
	socket_port = GetPrivateProfileInt("socket_show", "port", 0, p_config_path);
	ASSERT(0 != socket_port);
	*p_socket_port = socket_port;
}


void GetMysqlHost(const char *p_config_path, char *p_host, int host_size) {
	int copy_byte;

	ASSERT(NULL != p_config_path && NULL != p_host && 0 < host_size);
	copy_byte = GetPrivateProfileString("mysql", "host", NULL, p_host, host_size, p_config_path);
	ASSERT(0 != copy_byte);
}

void GetMysqlPort(const char *p_config_path, int *p_port) {
	int port;

	ASSERT(NULL != p_config_path && NULL != p_port);
	port = GetPrivateProfileInt("mysql", "port", 0, p_config_path);
	ASSERT(0 != port);
	*p_port = port;
}


void GetMysqlUser(const char *p_config_path, char *p_user, int user_size) {
	int copy_byte;

	ASSERT(NULL != p_config_path && NULL != p_user && 0 < user_size);
	copy_byte = GetPrivateProfileString("mysql", "user", NULL, p_user, user_size, p_config_path);
	ASSERT(0 != copy_byte);
}

void GetMysqlPassword(const char *p_config_path, char *p_password, int password_size) {
	int copy_byte;

	ASSERT(NULL != p_config_path && NULL != p_password && 0 < password_size);
	copy_byte = GetPrivateProfileString("mysql", "password", NULL, p_password, password_size, p_config_path);
	ASSERT(0 != copy_byte);
}

void GetVioDirectory(const char *p_config_path, char *p_dir, int dir_size) {
	int copy_byte;

	ASSERT(NULL != p_config_path && NULL != p_dir && 0 < dir_size);
	copy_byte = GetPrivateProfileString("violation", "path", NULL, p_dir, dir_size, p_config_path);
	ASSERT(0 != copy_byte);
}


